#include<bits/stdc++.h>
using namespace std;
int n;
typedef long long ll;
#define N 500005
#define INF 0x3f3f3f3f3f3f3f3f
vector<int>a[N];
char buf[N],*p1,*p2;
#define getchar() ((p1==p2&&(p2=(p1=buf)+fread(buf,1,N,stdin),p1==p2))?0:*p1++)
inline ll read(){
    char ch=getchar();ll x=0,f=1;
    while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9')
        x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
    return x*f;
}
struct fuck{
    int pos,len;
    fuck(){}
    fuck(int pos,int len):pos(pos),len(len){}
    bool operator <(const fuck &o)const{
        return len<o.len;
    }
}f[N*2];
vector<fuck>vf[N*2];
ll C,B[N];
int dc[N*2],sum[N*2],pc[N*2];
int cb[N*2];
vector<ll>va;
int main(){
    freopen("list.in","r",stdin);
    freopen("list.out","w",stdout);
    n=read();
    int tot=0;
    for(int i=1;i<=n;i++){
        int len;
        len=read();
        a[i].resize(len);
        tot+=len;
        for(int j=0;j<len;j++)a[i][j]=read();
    }
    C=read();
    for(int i=1;i<=n;i++)B[i]=(ll)read()*i;
    int cnt=0;
    for(int i=1;i<=n;i++){
        int len=a[i].size();
        for(int j=1;j<len;j++)f[++cnt]=fuck(a[i][j],a[i][j]-a[i][j-1]);
    }
    sort(f+1,f+cnt+1);
    for(int i=1;i<=cnt;i++)dc[i]=f[i].len;
    sort(dc+1,dc+cnt+1);
    int qwq=unique(dc+1,dc+cnt+1)-dc-1;
    for(int i=1;i<=cnt;i++){
        int tmp=lower_bound(dc+1,dc+qwq+1,f[i].len)-dc;
        vf[tmp].push_back(f[i]);
    }
    int m=0;
    for(int i=1;i<=n;i++){
        int len=a[i].size();
        for(int j=0;j<len;j++)pc[++m]=a[i][j];
    }
    sort(pc+1,pc+m+1);
    m=unique(pc+1,pc+m+1)-pc-1;
    for(int i=1;i<=n;i++){
        for(int j=0;j<a[i].size();j++){
            int val=lower_bound(pc+1,pc+m+1,a[i][j])-pc;
            cb[val]++;
        }
    }
    ll ans=0,res=tot;
    for(int i=1;i<=m;i++)ans+=B[cb[i]];
    ll mn=ans+tot*C;
    va.push_back(1);
    for(int i=1;i<=qwq;i++){
        ans+=C*(dc[i]-dc[i-1])*res;
        for(fuck tmp:vf[i]){
            int pp=lower_bound(pc+1,pc+m+1,tmp.pos)-pc;
            ans-=B[cb[pp]];
            cb[pp]--;
            ans+=B[cb[pp]];
        }
        res-=vf[i].size();
        if(ans+res*C<mn){
            va.clear();
            va.push_back(dc[i]+1);
            mn=ans+res*C;
        }
        else if(ans+res*C==mn)va.push_back(dc[i]+1);
    }
    printf("%lld %llu\n",mn,va.size());
    for(ll x:va)printf("%d ",x);
    return 0;
}